package com.sansi.bleFloodlight.adapter;

import android.text.TextUtils;

import androidx.core.graphics.ColorUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sansi.bleFloodlight.R;
import com.sansi.bleFloodlight.ble.bleInterface.IBleManage;
import com.sansi.bleFloodlight.db.TableDevice;
import com.sansi.bleFloodlight.utils.DrawableUtils;

public class HomeLightAdapter extends BaseQuickAdapter<TableDevice, BaseViewHolder> {
    private IBleManage iBleManage;
    private int colors[] = new int[2];

    public HomeLightAdapter(IBleManage iBleManage) {
        super(R.layout.layout_item_home_light);
        this.iBleManage = iBleManage;
    }

    @Override
    protected void convert(BaseViewHolder helper, TableDevice myDevice) {
        helper.setText(R.id.tv_name, TextUtils.isEmpty(myDevice.getBluetoothDevice().getName()) ? "SanSi" : myDevice.getBluetoothDevice().getName())
                .setText(R.id.tv_address, myDevice.getMac());
        if (myDevice.getColor() == 0) {
            helper.getView(R.id.rl_bg).setBackgroundResource(R.drawable.shape_bg_home_search_light);
        } else {
            colors[0] = ColorUtils.setAlphaComponent(myDevice.getColor(), 128);
            colors[1] = myDevice.getColor();
            DrawableUtils.getGradientDrawable(helper.getView(R.id.rl_bg), colors,mContext);
        }
    }
}
